$(function () {
    $.idcode.setCode()
    $.validator.addMethod("truephone", function (value) {
        return /^1[3456789]\d{9}$/.test(value)
    })
    $.validator.addMethod("truepwd", function (value) {
        return /^[0-9A-Za-z]{8,20}$/.test(value)
    })
    $("form").validate({
        wrapper: "em",
        rules: {
            uphone: {
                required: true,
                truephone: true
            },
            upwd: {
                required: true,
                truepwd: true
            },
            uagree: "required"

        },
        messages: {
            uphone: {
                required: "手机号不能为空!",
                truephone: "请输入正确的手机号码"
            },
            upwd: {
                required: "密码不能为空!",
                truepwd: "密码必须为8到20位数字和字母组合"
            },
            uagree:"请同意我们的协议!"
        },
        success: function(label) {
            label.text("验证通过!")
            
           
        },
        submitHandler(from) {

            var IsBy = $.idcode.validateCode()
            if (!IsBy) {
                layer.msg('验证码错误,请重新输入');
                layer.alert('验证码错误,请重新输入');
                return false;
            }

        
            var dataStr = $(from).serialize();
            console.log(dataStr)
            $.ajax({
                url: "http://127.0.0.1:8080/api/reg", // url地址
                data: dataStr, // 参数
                async: true, //异步
                type: "post", //请求方式
                dataType: "json", //返回的数据格式
            }).done(function (res) {
                console.log(res)
                layer.msg(res.msg);
                layer.alert(res.msg);
                
            })
          
   
        }
    })









})